<?php
namespace app\SuperAdmin\controller;
use think\Db;
use think\Controller;
use think\Session;
class ShaituController extends Controller
{
    public function _initialize()
    {
        if (!Session::has('adminid'))
        {
            $this->redirect('index/index/index');
        }
    }

    public function index()
    {

        $c=Db::table('shaitu')
            ->alias(['shaitu'=>'a','users'=>'b'])
            ->join('users','b.uid= a.uid')
            ->order('sid asc')
            ->paginate(5);
        $this->assign('list', $c);
        return $this->fetch('shaitu');

    }
    public function xiangqing()
    {
        $sid=input('id');
        $shaitu=\db('shaitu')->where('sid',$sid)->alias('d')->join('users u','u.uid=d.uid')->find();
        $this->assign('shaitu',$shaitu);
        $xiangqing=\db('discussion')->where('sid',$sid)->alias('d')->join('users u','u.uid=d.uid')->paginate(30);
        $this->assign('list', $xiangqing);
        return $this->fetch('xiangqing');
    }
    public function delete()
    {
        $sid = input('id');
        if (db("discussion")->delete($sid)) {
            $this->success("删除成功");
        } else {
            $this->error("删除失败");
        }

    }
    public function delete1(){
        $sid=input('id');
        $shaitu=Db::name("shaitu")->find($sid);
        $pic=$shaitu["spic"];
        $file=ROOT_PATH."public".DS."static".DS. 'img'.DS.'shaitu'.DS.$pic;
        if (file_exists($file)) {
            unlink($file);
        }
        if (Db::table("shaitu")->delete($sid)){
            $this->success("删除成功");
        }
        else{
            $this->error("删除失败");
        }
    }

}